var n = {k: 2}
var a = {
  name: 'kardel',
  age: 10,
  b: {
    c: {}
  },
  o: {}
}
a.b.c.d = a;
a.b.c.f = a;
a.o = a;
// a.b.c.k = n;
n.f = a;

function cycle(obj) {
  let map = new WeakMap();
  map.set(obj, 1);
  function deepCycle(innerObj) {
    console.log(innerObj)
    let cycleList = [];
    for (const key in innerObj) {
      if (Object.hasOwnProperty.call(innerObj, key)) {
        const element = innerObj[key];
        // 递归调用
        if(typeof element === 'object') {
          if(map.has(element)) {
            cycleList.push(key);
          } else {
            map.set(element, 1);
            cycleList = cycleList.concat(deepCycle(element));
          }
        }
      }
    }
    return cycleList;
  }
  let as = deepCycle(obj);
  console.log(as);
}

cycle(a);